var setting = {
	async: {
		enable: true,
		url: getUrl
	},
	data: {
		simpleData: {
		  enable: true
	    }
	},
	view: {
		expandSpeed: ""
	},
	callback: {
		beforeExpand: beforeExpand,
		onAsyncSuccess: onAsyncSuccess,
		onAsyncError: onAsyncError
	}
};
function getUrl(treeId, treeNode) {
	var sign=treeNode.id.substr(0,1);
	var cid=treeNode.id.substr(1);
	if(sign=='C'){
		return "../base/queryTree_Ban.action?cid="+cid+"&urlSign=anmeterManager";
	}else if(sign=="B"){
		return "../base/queryTree_Unit.action?bid="+cid+"&urlSign=anmeterManager";
	}else if(sign=="U"){
		return "../base/queryTree_Room.action?uid="+cid+"&urlSign=anmeterManager";
	}
};
function beforeExpand(treeId, treeNode) {
	if (!treeNode.isAjaxing) {
		ajaxGetNodes(treeNode, "refresh");
		return true;
	} else {
		alert("正在下载数据中，请稍后展开节点。。。");
		return false;
	}
};
function ajaxGetNodes(treeNode, reloadType) {
	var zTree = $.fn.zTree.getZTreeObj("menup");
	if (reloadType == "refresh") {
		treeNode.icon = "../script/ztree/css/zTreeStyle/img/loading.gif";
		zTree.updateNode(treeNode);
	}
	zTree.reAsyncChildNodes(treeNode, reloadType, true);
};
function onAsyncError(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {
	var zTree = $.fn.zTree.getZTreeObj("menup");
	alert("异步获取数据出现异常。");
	treeNode.icon = "";
	zTree.updateNode(treeNode);
};
function onAsyncSuccess(event, treeId, treeNode, msg) {
	var zTree = $.fn.zTree.getZTreeObj("menup"),
	totalCount = treeNode.count;
	treeNode.icon = "";
	zTree.updateNode(treeNode);
	zTree.selectNode(treeNode.children[0]);
};

$(document).ready(function(){
	$.post("../base/query_RoomInfo.action",{"urlSign":"anmeterManager"},function(result){
		$.fn.zTree.init($("#menup"), setting, result.communitys);
	});
	
});
function remove(acode){
	$('#myModal').modal('show');
	$.post("../dashboard/remove_Anmeter.action",{"anmeter.acode":acode}, function(result) {
		if(result.msg=="succ"){
			$('#myModal').modal('hide');
			$("#alertinfo").html("电表删除成功。");
			$("#closewin").bind("click",function(){
				$("#closewin").unbind("click");
				$('#myinfo').modal('hide');
				window.location.reload();
			});
			$('#myinfo').modal('show');
		}else{
			$('#myModal').modal('hide');
			$("#alertinfo").html(result.msg);
			$('#myinfo').modal('show');
		}
	});
}
function view(acode){
	window.location.assign("../dashboard/view_Anmeter.action?anmeter.acode="+acode);
}